"""版本一GenericAPIView"""
#
# from rest_framework.generics import GenericAPIView
# from meiduo_admin.serializer.images_serializer import *
# from meiduo_admin.pages import MyPage
# from rest_framework.response import Response
#
#
# # 请求方式： GET /meiduo_admin/skus/images/
# class ImagesView(GenericAPIView):
#     serializer_class = ImageSerializer
#     queryset = SKUImage.objects.all()
#     pagination_class = MyPage
#
#     """展示所有商品图片"""
#     def get(self, request):
#         image = self.get_queryset()
#         page = self.paginate_queryset(image)
#         if page:
#             page_serializer = self.get_serializer(page, many=True)
#             return self.get_paginated_response(page_serializer.data)
#         serializer = ImageSerializer(image, many=True)
#         return Response(serializer.data)
#
#     """增加商品图片"""
#     def post(self, request):
#         image_obj = self.request.data
#         serializer = ImageSerializer(data=image_obj)
#         serializer.is_valid(raise_exception=True)
#         serializer.save()
#         return Response(serializer.data, status=201)
#
#
# class SKUSimpleView(GenericAPIView):
#     serializer_class = SKUImageSerializer
#     queryset = SKU.objects.all()
#
#     def get(self, request):
#         """获取SKU商品下拉"""
#         skus = self.get_queryset()
#         serializer = self.get_serializer(skus, many=True)
#         return Response(serializer.data)
#
#
# # 请求方式： GET /meiduo_admin/skus/images/(?P<pk>\d+)/
# class SKUImageSimpleView(GenericAPIView):
#     serializer_class = ImageSerializer
#     queryset = SKUImage.objects.all()
#
#     def get(self, request, pk):
#         sku_image = self.get_object()
#         serializer = self.get_serializer(sku_image)
#         return Response(serializer.data)
#
#     def put(self, request, pk):
#         sku_obj = self.get_object()
#         serializer = ImageSerializer(instance=sku_obj, data=request.data)
#         serializer.is_valid(raise_exception=True)
#         serializer.save()
#         return Response(serializer.data)
#
#     def delete(self, request, pk):
#         brand_obj = self.get_object()
#         brand_obj.delete()
#         return Response({})


"""版本二ModelViewSet"""

from meiduo_admin.serializer.images_serializer import *
from meiduo_admin.pages import MyPage
from rest_framework.viewsets import ModelViewSet
from rest_framework.generics import ListAPIView


# 请求方式： GET /meiduo_admin/skus/images/
class ImagesView(ModelViewSet):
    """展示所有商品图片"""
    serializer_class = ImageSerializer
    queryset = SKUImage.objects.all()
    pagination_class = MyPage


class SKUSimpleView(ListAPIView):
    serializer_class = SKUImageSerializer
    queryset = SKU.objects.all()



